package com.alinesno.cloud.initializr.starter.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alinesno.cloud.initializr.starter.entity.StaticCountEntity;
import com.alinesno.cloud.initializr.starter.repository.StaticMapper;
import com.alinesno.cloud.initializr.starter.service.IStaticService;
import com.alinesno.cloud.initializr.starter.vo.StaticDataVo;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

/**
 * @author WeiXiaoJin
 * @date 2021/10/12
 */
@Service
public class StaticServiceImpl extends ServiceImpl<StaticMapper , StaticCountEntity> implements IStaticService {
	
    @Autowired
    private StaticMapper staticMapper;

    /**
     * 计算统计数据
     *
     * @return 统计数据对象
     */
    @Override
    public StaticDataVo computeStatic() {
        return staticMapper.fetchStaticData();
    }

	@Override
	public void addGenAppCount() {
		StaticCountEntity e = this.getById(1) ; 
		if(e == null) {
			e = new StaticCountEntity() ; 
			e.setId(1) ; 
			e.setGenAppCount(1);
			e.setGenDatabaseCount(1);
		}else {
			e.setGenAppCount(e.getGenAppCount()+1);
		}
		this.saveOrUpdate(e) ;
	}

	@Override
	public void addGenDatabaseCount() {
		StaticCountEntity e = this.getById(1) ; 
		if(e == null) {
			e = new StaticCountEntity() ; 
			e.setId(1) ; 
			e.setGenAppCount(1);
			e.setGenDatabaseCount(1);
		}else {
			e.setGenDatabaseCount(e.getGenDatabaseCount()+1);
		}
		this.saveOrUpdate(e) ;
	}
}
